package com.douwong.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.model.AppInfos;
import com.douwong.student.model.Holder;

import java.util.ArrayList;

/**
 * @autor yichao
 * @time 2016/11/2411:26
 * @des  应用和在线学习Adapter的基类
 */
public abstract class BaseAppAdapter extends BaseAdapter {
    protected ArrayList<AppInfos> mOnLineList;
    protected Context mContext;

    public void setOnLineList(ArrayList<AppInfos> onLineList) {
        mOnLineList = onLineList;
    }

    public BaseAppAdapter(ArrayList<AppInfos> onLineList, Context context) {
        mOnLineList = onLineList;
        mContext = context;
    }

    @Override
    public int getCount() {
        if (mOnLineList==null||mOnLineList.size()==0){
            return 0;
        }
        return mOnLineList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.application_gv_item, null);
            holder.title = (TextView) convertView.findViewById(R.id.appgvitem_name);
            holder.drawb = (ImageView) convertView.findViewById(R.id.appgvitem_icon);
            holder.pwd_on = (RelativeLayout) convertView.findViewById(R.id.pwd_rl);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        setViewDate(holder,mOnLineList,position);
        //设置数据


        return convertView;
    }

    /**
     * 设置item数据
     * @param holder
     * @param onLineList
     * @param position
     */
    protected abstract void setViewDate(Holder holder, ArrayList<AppInfos> onLineList, int position) ;


}

